package org.popupcommunication.dao.impl;


import javax.persistence.Query;
import org.popupcommunication.dao.MessageDAO;
import org.popupcommunication.model.Message;
import org.springframework.stereotype.Repository;


@Repository
public class MessageJpa extends GenericRepositoryJpa<Message> implements MessageDAO{

	@Override
	public Message findByTitle(String name) {
		Query query =  this.getEntityManager().createQuery("SELECT m FROM Message m WHERE m.titre=:title");
		query.setParameter("title", name);
		Message msg = (Message) query.getSingleResult();		
		return msg;
	}

//
//	@Override
//	public Message findById(int id) {
//		TypedQuery<Message> query =  this.getEntityManager().createQuery("SELECT m FROM Message m", Message.class);
//		List<Message> results = query.getResultList();					
//		Message msg=null;
//		for(Message item:results){
//			if (item.getIdMessage() == id ){
//			   msg = item;
//			}   
//		}		
//		return msg;
//	}
	



}
